package com.springboot.demo.controller;

import com.springboot.demo.model.User;
import com.springboot.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Controller类上加了@RestController注解
 * 相当于类上加@Controller注解
 * 然后每个方法加@ResponseBody注解
 */
//@Controller
@RestController
@EnableAutoConfiguration
public class UserController {

    @Autowired
    private UserService userService;

//    @ResponseBody
    @RequestMapping(value = "/get")
    public User getUser() {
        User user = new User();
        user.setId(213);
        user.setUsername("张三");
        return user;
    }

    @RequestMapping("/getlist")
    public List<User> selectUserList() {
        List<User> users = userService.selectUserList();
        return users;
    }
}
